# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html


class BirdPipeline(object):
    def process_item(self, item, spider):
        return item
import MySQLdb
def dbHandle():
    conn = MySQLdb.connect(
        host='127.0.0.1',
        user='root',
        passwd='root',
        db='test',
        charset='utf8',
        # use_unicode=False
    )
    return conn

class BirdPipeline(object):
    def process_item(self, item, spider):
        dbObject = dbHandle()
        cursor = dbObject.cursor()
        sql = 'insert into bird(item,model,title,content,picture) values (%s,%s,%s,%s,%s)'

        try:
            cursor.execute(sql, (item['item'], item['model'], item['title'], item['content'], item['picture']))
            dbObject.commit()
        except Exception,e:
            print e
            dbObject.rollback()

        return item